<template>
  <div class="dashboard-container body-min-width">
    <h2 class="head-big-title">Log Aktiviti</h2>
    <Pathnavigation style="margin-left: 3%;"></Pathnavigation>
    <div style="width: 92%;height: 120px;margin: 20px 4% 0 4%;padding: 10px 0 0 20px;border-radius: 10px;background-color: white;">
      <el-form label-position="top" label-width="80px" :inline="true" class="head-search" :model="searchData" style="float: left;text-align: left;">
        <el-form-item label="Nama" width="188">
          <el-input v-model="searchData.operUserName" @blur="getResetLoadData" class="input-width" placeholder="Nama"></el-input>
        </el-form-item>
        <el-form-item label="Tarikh" width="188">
          <el-date-picker
            class="input-width"
            @input="changeNew($event)"
            @change="getResetLoadData"
            value-format="yyyy-MM-dd[T]HH:mm:ss[.000Z]"
            v-model="searchData.startTime"
            type="datetime"
            placeholder="Tarikh">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="Kategori" width="188">
          <el-select v-model="searchData.operType" @change="getResetLoadData" class="input-width" placeholder="Kategori">
            <el-option label="Semua" value=""></el-option>
            <el-option label="Log Masuk" value="login"></el-option>
            <el-option label="Cipta" value="Create"></el-option>
            <el-option label="Tambah" value="Add"></el-option>
            <el-option label="Edit" value="Edit"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="tableData"
      style="width: 92%;margin: 20px 4% 0 4%;padding-left: 10px;border-radius: 20px">
      <el-table-column prop="operCreateTime" label="Tarikh" align="center">
        <template slot-scope="scope">
          {{ $getTime(scope.row.operCreateTime)}}
        </template>
      </el-table-column>
      <el-table-column prop="operUserId" label="Nama"></el-table-column>
      <el-table-column prop="operType" label="Kategori"></el-table-column>
      <el-table-column prop="operDesc" label="Aktiviti"></el-table-column>
      <el-table-column label="Tindakan" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            style="font-size: 26px;padding: 0;background-color: rgb(56,96,134);border: 0;margin-left: 18px;"
            @click="showContent(scope.row)">
            <svg-icon icon-class="ico_view"></svg-icon></el-button>
        </template>
      </el-table-column>
<!--      <el-table-column prop="operMethod" label="Penerangan"></el-table-column>-->
    </el-table>
    <el-pagination
      style="clear: top;float: right;margin: 15px 3% 15px 0;"
      layout="prev, pager, next"
      :page-size="searchData.pageNum"
      @current-change="handleCurrentChange"
      :current-page="searchData.pageIndex"
      :total="total">
    </el-pagination>
    <el-dialog
      :title="$getTime(operCreateTime)"
      :visible.sync="tipDialogVisible"
      width="30%">
      <p style="display: block;text-align: left;font-size: 14px;margin-bottom: 10px;"><span style="font-size: 17px;display: block;color: black;">Penerangan:</span>{{operMethod?operMethod:'null'}}</p>
      <p style="display: block;text-align: left;font-size: 14px;margin-bottom: 10px;"><span style="font-size: 17px;display: block;color: black;">Hantar Data:</span>{{operReqParam?operReqParam:'null'}}</p>
      <p style="display: block;text-align: left;font-size: 14px;margin-bottom: 10px;"><span style="font-size: 17px;display: block;color: black;">Kembalikan Data:</span>{{operResParam?operResParam:'null'}}</p>
      <span slot="footer" class="dialog-footer">
    <el-button @click="tipDialogVisible = false">Balik</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { operation_log_queryApi } from '@/api/user'

export default {
  name: 'Activityrecord',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data() {
    return {
      tableData: [],
      searchData: {
        pageNum: 10,
        pageIndex: 1
      },
      loading: false,
      tipDialogVisible: false,
      orderChart: '',
      operReqParam: '',
      operResParam: '',
      operMethod: '',
      operCreateTime: '',
      total: 0
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    changeNew() {
      this.$forceUpdate()
    },
    showContent(row) {
      this.operReqParam = row.operReqParam
      this.operResParam = row.operResParam
      this.operMethod = row.operMethod
      this.operCreateTime = row.operCreateTime
      this.tipDialogVisible = true
    },
    handleCurrentChange(val) {
      this.searchData.pageIndex = val
      this.loadData()
    },
    getResetLoadData() {
      this.searchData.pageIndex = 1
      this.loadData()
    },
    loadData() {
      operation_log_queryApi(this.searchData).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
      }).catch(err => {
        console.log(err)
      })
    } // 得到数据表格
  }
}
</script>

<style lang="scss" scoped>
  .head-big-title{
    text-align: left;
    font-size: 20px;
    margin: 20px 0 0 3%;
  }
  .dashboard-container{
    margin-top: 20px;
    text-align: center;
  }

</style>
<style scoped>
  /deep/.head-search label{
    line-height: 30px;
  }
</style>
